<template>
	<layout>
		<uv-navbar
		  :fixed="false"
		  :title="title"
		  left-arrow
		  @leftClick="$onClickLeft"
		/>
		<view class="container">
			<view class="my-background">
				<view  style="">
					<view class="flex justify-between p-3 align-center">
						<view class="flex">
							<image :src="member.avatar ? member.avatar : '/static/images/mine/default.png'" 
							class="rounded-circle avatar-img"></image>
							<view class="flex flex-column text-white justify-center align-cente ml-2">
								<text class="nick-text">{{member.nickname}}</text>
								<text class="id-text">{{roleName}}</text>
							</view>
						</view>
						<view  class="mt-2 mr-4"  @tap="gopage('/pages/components/pages/mine/index')">
							<image src="/static/images/mine/set.png" class="icon-img"></image>
						</view>
					</view>
				</view>
				<view style="padding: 0 30rpx;">
					
					<!-- user box begin -->
					<view class="d-flex flex-column bg-white user-box">

						<!-- user grid begin -->
						<view class="w-100 flex align-items-center just-content-center">
							<view class="user-grid" @click="gopage('/pages/components/pages/mine/list')">
								<view class="value font-size-extra-lg font-weight-bold text-color-base position-relative">
										<uv-badge type="error" max="99" :value="noticeCount" :absolute="true" :offset="[-5,-5]"></uv-badge>
									<image :src="VUE_APP_RESOURCES_URL + '/static/images/12.png'" class="icon-img"></image>
								</view>
								<view class="font-size-sm text-color-assist">通知</view>
							</view>
							<view class="user-grid"  @click="gopage('/pages/components/pages/msg/wait')">
								<view class="value font-size-extra-lg font-weight-bold text-color-base position-relative">
									<uv-badge type="error" max="99" :value="waitCount" :absolute="true" :offset="[-10,-10]"></uv-badge>
									<image :src="VUE_APP_RESOURCES_URL + '/static/images/13.png'" class="icon-img"></image>
								</view>
								<view class="font-size-sm text-color-assist">待办</view>
							</view>
							<view class="user-grid" @click="gopage('/pages/components/pages/msg/exam')">
								<view class="value font-size-extra-lg font-weight-bold text-color-base position-relative">
									<uv-badge type="error" max="99" :value="checkCount" :absolute="true" :offset="[-10,-10]"></uv-badge>
									<image :src="VUE_APP_RESOURCES_URL + '/static/images/14.png'" class="icon-img"></image>
								</view>
								<view class="font-size-sm text-color-assist">审批</view>
							</view>
				
						</view>
						<!-- user grid end -->
					</view>
					<!-- user box end -->

				</view>
			
			</view>
			
			<view class="bg-white px-3 mx-3 mb-1">
				<view class="font-size-sm mb-3 pt-3">
					<text>客户管理</text>
				</view>
				<uv-grid :col="4" :border="false" @click="onGrid" >
					<uv-grid-item v-for="(item, index) in orderTabs" :key="index" :customStyle="customStyle" @click="item.name == '客户' ? gopage2(item.path) : gopage(item.path)">
						<uv-icon  :name="item.image" :size="30" ></uv-icon>
						<text class="p-1 font-size-sm">{{ item.title }}</text>
					</uv-grid-item>
				</uv-grid>
			</view>
			
			<view class="bg-white px-3 mx-3 mb-1">
				<view class="font-size-sm mb-3 pt-3">
					<text>办公</text>
				</view>
				<uv-grid :col="4" :border="false" @click="onGrid" >
					<uv-grid-item v-for="(item, index) in orderTabs2" :key="index" :customStyle="customStyle" @click="gopage(item.path)">
						<uv-icon  :name="item.image" :size="30" ></uv-icon>
						<text class="p-1 font-size-sm">{{ item.title }}</text>
					</uv-grid-item>
				</uv-grid>
			</view>
			
			<view class="bg-white px-3 mx-3 mb-1">
				<view class="font-size-sm mb-3 pt-3">
					<text>数据分析</text>
				</view>
				<uv-grid :col="4" :border="false" @click="onGrid" >
					<uv-grid-item v-for="(item, index) in orderTabs3" :key="index" :customStyle="customStyle"  @click="gopage(item.path)">
						<uv-icon  :name="item.image" :size="30" ></uv-icon>
						<text class="p-1 font-size-sm">{{ item.title }}</text>
					</uv-grid-item>
				</uv-grid>
			</view>
			<view class="bg-white px-3 mx-3 mb-1">
				<view class="font-size-sm mb-3 pt-3">
					<text>帮助中心</text>
				</view>
				<uv-grid :col="4" :border="false" @click="onGrid" >
					<uv-grid-item v-for="(item, index) in orderTabs4" :key="index" :customStyle="customStyle"  @click="gopage(item.path)">
						<uv-icon  :name="item.image" :size="30" ></uv-icon>
						<text class="p-1 font-size-sm">{{ item.title }}</text>
					</uv-grid-item>
				</uv-grid>
			</view>
		</view>
	</layout>
</template>

<script setup>
import {
  ref,
  computed
} from 'vue'
import { useMainStore } from '@/store/store'
import { storeToRefs } from 'pinia'
import { onLoad,onShow} from '@dcloudio/uni-app'
import {
  userGetUserInfo
} from '@/api/user'
import { VUE_APP_RESOURCES_URL } from "@/config";
const main = useMainStore()
const { member,isLogin,indexCount } = storeToRefs(main)

const title = ref('个人中心')
const services = ref([])
const orderTabs = [
	{
		title: '公海客户',
		index: 1,
		image: VUE_APP_RESOURCES_URL + '/static/images/index002.png',
		path: '/pages/components/pages/customer/open'
	},
	{
		title: '线索',
		index: 1,
		image: VUE_APP_RESOURCES_URL + '/static/images/2.png',
		path: '/pages/components/pages/clues/index'
	},
	{
		title: '客户',
		index: 2,
		image: VUE_APP_RESOURCES_URL + '/static/images/1.png',
		path: VUE_APP_RESOURCES_URL + '/pages/customer/index'
	},
	{
		title: '订单',
		index: 3,
		image: VUE_APP_RESOURCES_URL + '/static/images/index006.png',
		path: '/pages/components/pages/contract/index'
	},
	{
		title: '产品',
		index: 4,
		image: VUE_APP_RESOURCES_URL + '/static/images/8.png',
		path: '/pages/components/pages/product/index'
	},

	
]

const orderTabs2 = [
	{
		title: '公告',
		index: 1,
		image: VUE_APP_RESOURCES_URL + '/static/images/11.png',
		path: '/pages/components/pages/mine/list'
	},
	{
		title: '跟进记录',
		index: 1,
		image: VUE_APP_RESOURCES_URL + '/static/images/index004.png',
		path: '/pages/components/pages/record/index'
	},
]

const orderTabs3 = [
	{
		title: '业绩完成度',
		index: 1,
		image: VUE_APP_RESOURCES_URL + '/static/images/24.png',
		path: '/pages/components/pages/analysis/achievement'
	},
	{
		title: '销售简报',
		index: 1,
		image: VUE_APP_RESOURCES_URL + '/static/images/10.png',
		path: '/pages/components/pages/analysis/sales'
	},
	{
		title: '排行榜',
		index: 1,
		image: VUE_APP_RESOURCES_URL + '/static/images/9.png',
		path: '/pages/components/pages/analysis/rank'
	},
]

const orderTabs4 = [
	{
		title: '消息推送',
		index: 1,
		image: VUE_APP_RESOURCES_URL + '/static/images/25.png',
		path: '/pages/components/pages/mine/wechat'
	},
]

const customStyle = computed(() =>{
	return {
		 paddingBottom:'40rpx',
		}
})

const roleName = ref('--')

const waitCount = ref(0)
const checkCount = ref(0)
const noticeCount = ref(0)

	
onShow(() => {
	noticeCount.value = indexCount.value.brieCountVO.count13
	waitCount.value = indexCount.value.followBusinessCount + indexCount.value.followCluesCount + indexCount.value.followCustomerCount
	checkCount.value = indexCount.value.contractCheckCount + indexCount.value.invoiceCheckCount + indexCount.value.receivablesCheckCount
	getUserInfo();
})

const toDetail = (page,index) => {
	uni.navigateTo({
		url: page + '?current=' + index
	})
}
const getUserInfo = async() => {
	let data = await userGetUserInfo()
	if (data) {
		main.SET_MEMBER(data)
		if(data.roles.length > 0){
			roleName.value = data.roles[0].name
		}
	}
}

const gopage = (url) => {
	if(url == ''){
		uni.showToast({
			icon: 'error',
			title: '开发中，未开放'
		})
		
		return
	}
	uni.navigateTo({
		url
	})
}

const gopage2 = (url) =>{
	if(url == ''){
		uni.showToast({
			icon: 'error',
			title: '开发中，未开放'
		})
		
		return
	}
	uni.switchTab({
		url
	}) 

}

</script>

<style lang="scss" scoped>
	page {
		height: auto;
		min-height: 100%;
	}
	
	.my-background {
		background: linear-gradient(-180deg, #b3e8fb 0, #ffffff 100%, #ffffff 100%) !important
	}
	
	.avatar-img {
		width: 100rpx;
		height: 100rpx;
	}
	.nick-text {
		font-size: 24rpx;
		color: #333;
		//font-weight: bold;
	}
	.id-text {
		font-size: 22rpx;
		color: #333;
	}
	.icon-img {
		width: 50rpx;
		height: 50rpx;
	}
	.vip-box {
		position: relative;
		text-align: center;
		.vip-box-content {
			height: 100rpx;
			.vip-box-left{
				position: absolute;top: 38rpx;left:60rpx;z-index: 2;
			}
			.vip-box-right {
				color: #ffffff;position: absolute;top: 45rpx;right:60rpx;z-index: 2;
			}
		}
	}
	.font-size-26 {
		font-size: 28rpx;
	}
	.font-size-24 {
		font-size: 24rpx;
	}
	.vip-bg-img {
		position: absolute;
		top: 10rpx;
		left: 0;
		right:0;
		margin:auto;
		width:700rpx
	}
	
	.item-image {
		width: 40rpx;
		height: 40rpx;
	}

	.bg {
		width: 100%;
		height: calc(410 / 594 * 750rpx);
	}

	.hym-btn {
		position: absolute;
		top: 40rpx;
		right: 40rpx;
		color: $color-primary;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 50rem;
		font-size: $font-size-sm;
		box-shadow: 0 0 20rpx rgba(66, 66, 66, 0.1);

		&::after {
			border: 0;
		}

		image {
			width: 30rpx;
			height: 30rpx;
			margin-right: 10rpx;
		}
	}

	.user-box {
		position: relative;
		border-radius: 8rpx;
		margin-bottom: 10rpx;
		//margin-top: 40rpx;
		box-shadow: $box-shadow;
	}

	// .avatar {
	// 	position: relative;
	// 	margin-top: -35rpx;
	// 	margin-left: 35rpx;
	// 	margin-right: 35rpx;
	// 	width: 160rpx;
	// 	height: 160rpx;
	// 	border-radius: 20rpx;
	// 	display: flex;
	// 	align-items: center;
	// 	justify-content: center;
	// 	background-color: #FFFFFF;
	// 	box-shadow: 0 0 20rpx rgba($color: #000000, $alpha: 0.2);

	// 	image {
	// 		width: 140rpx;
	// 		height: 140rpx;
	// 		border-radius: 100%;
	// 	}

	// 	.badge {
	// 		position: absolute;
	// 		right: -10rpx;
	// 		bottom: -10rpx;
	// 		background-color: #FFFFFF;
	// 		border-radius: 50rem;
	// 		display: flex;
	// 		align-items: center;
	// 		justify-content: center;
	// 		color: $color-warning;
	// 		font-size: 24rpx;
	// 		padding: 8rpx 16rpx;
	// 		box-shadow: 0 0 20rpx rgba($color: #000000, $alpha: 0.2);

	// 		image {
	// 			width: 30rpx;
	// 			height: 30rpx;
	// 		}
	// 	}
	// }

	.level-benefit {
		margin-left: 35rpx;
		padding: 10rpx 0 10rpx 30rpx;
		border-radius: 50rem 0 0 50rem;
	}

	.user-grid {
		width: 33%;
		padding: 30rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		.value {
			margin-bottom: 20rpx;
		}
	}

	.level-benefit-box {
		border-radius: 8rpx;
		margin-bottom: 30rpx;
		box-shadow: 0 10rpx 8rpx rgba($color: #878889, $alpha: 0.1);
		width: 100%;
		display: flex;
		padding: 30rpx;
		flex-direction: column;
		background-color: #FFFFFF;

		.row {
			display: flex;
			padding: 30rpx 0 20rpx;
			justify-content: space-around;
			align-items: center;

			.grid {
				width: 20%;
				display: flex;
				flex-direction: column;
				font-size: $font-size-sm;
				color: $text-color-assist;
				align-items: center;

				image {
					width: 80rpx;
					height: 80rpx;
					margin-bottom: 10rpx;
				}

			}
		}
	}


	.banner {
		width: 100%;
		border-radius: 8rpx;
		margin-bottom: 30rpx;
	}

	.service-box  {
		width: 100%;
		background-color: #FFFFFF;
		padding: 32rpx 30rpx 10rpx;
		box-shadow: $box-shadow;

		// .row {
		// 	display: flex;
		// 	flex-wrap: wrap;
		// 	color: $text-color-assist;
		// 	font-size: $font-size-sm;
		// 	padding-bottom: -40rpx;

		// 	.grid {
		// 		display: flex;
		// 		flex-direction: column;
		// 		justify-content: center;
		// 		align-items: center;
		// 		margin-bottom: 40rpx;
		// 		width: 25%;
		// 		position: relative;

		// 		image {
		// 			width: 80rpx;
		// 			height: 80rpx;
		// 			margin-bottom: 20rpx;
		// 		}
		// 	}

		// 	.opacity-0 {
		// 		position: absolute;
		// 		width: 100%;
		// 		height: 100%;
		// 		opacity: 0;
		// 		z-index: 10;
		// 	}

		// }
	}
</style>
